﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace WebUI
{
    // Примечание: Инструкции по включению классического режима IIS6 или IIS7 
    // см. по ссылке http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            #region IgnoreRoute
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            // Решение проблемы с exeption in ControllerFactore
            routes.IgnoreRoute("{*alljs}", new { alljs = @".*\.js(/.*)?" });
            routes.IgnoreRoute("{*allgif}", new { allgif = @".*\.gif(/.*)?" });
            routes.IgnoreRoute("{*allcss}", new { allcss = @".*\.css(/.*)?" });
            routes.IgnoreRoute("{*allhtml}", new { allhtml = @".*\.html(/.*)?" });
            routes.IgnoreRoute("{*allswf}", new { allswf = @".*\.swf(/.*)?" });
            routes.IgnoreRoute("{*allpng}", new { allpng = @".*\.png(/.*)?" });
            routes.IgnoreRoute("{*allpdf}", new { allpdf = @".*\.pdf(/.*)?" });
            routes.IgnoreRoute("{*allcsv}", new { allpdf = @".*\.csv(/.*)?" });
            routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
            //
            #endregion
            /*
            #region Post
            routes.MapRoute(
                null, // Имя маршрута
                "", // URL-адрес с параметрами
                new { controller = "Post", action = "List", page = 1 } // Параметры по умолчанию
            );

            routes.MapRoute(
                null,
                "Page{page}",
                new { controller = "Post", action = "List", page = @"\d+" }
            );


            routes.MapRoute(
                null,
                "Best/{time}",
                new { controller = "Post", action = "Best", page = 1, time = (string)null }
            );

            routes.MapRoute(
                null,
                "Best/{time}/Page{page}",
                new { controller = "Post", action = "Best", page = (int?)null, time = (string)null }
            );

            routes.MapRoute(
                null,
                "AddPost",
                new { controller = "Post", action = "AddPost" }
            );
            
            routes.MapRoute(
                null,
                "{filter}",
                new { controller = "Post", action = "FilterPost", page = 1, filter = (string)null }
            );            
            
            routes.MapRoute(
                null,
                "{filter}/Page{page}",
                new { controller = "Post", action = "FilterPost", page = (int?)null, filter = (string)null }
            );


            #endregion


            #region Admin

            routes.MapRoute(
                null,
                "Admin",
                new { controller = "Admin", action = "index"}
            );            
            

            #endregion
            */


            routes.MapRoute(
                "ShowTask", // Имя маршрута
                "showtask/{id}", // URL-адрес с параметрами
                new { controller = "Task", action = "ShowTask", id = (int?)null } // Параметры по умолчанию
            );

            routes.MapRoute(
                null, // Имя маршрута
                "", // URL-адрес с параметрами
                new { controller = "Navigation", action = "Home" } // Параметры по умолчанию
            );

            routes.MapRoute(
                null, // Имя маршрута
                "task", // URL-адрес с параметрами
                new { controller = "Task", action = "TasksList" } // Параметры по умолчанию
            );

            routes.MapRoute(null, "{controller}/{action}");

        }

        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory());

        }
    }
}